<template>
    <div class='BtmEditAnim'>
        <transition name="fade">
            <div class="back-btn" v-show="modelValue" @click="$emit('update:modelValue', false)">
                <!-- <el-button @click="$emit('update:modelValue', false)" size="mini" type="text" icon="el-icon-arrow-down">收起</el-button> -->
                <div class="t1"></div>
                <div class="t2"></div>
            </div>
        </transition>
        <div class="adjust" v-show="modelValue" :class="{'click':isMobile}" @mousedown="mousedown" @mouseup="mouseup"></div>
        <!-- 视觉拉满 -->
        <div v-if="!isEffect">
            <transition name="fade">
                <div class="pagination" v-show="!modelValue">
                    <slot name="pagination"></slot>
                </div>
            </transition>
            <transition name="fade">
                <div class="buttom" v-show="modelValue" :style="{'height':mobileY+'px'}">
                    <el-scrollbar>
                        <slot></slot>
                    </el-scrollbar>
                </div>
            </transition>
        </div>
        <!-- 高性能模式 -->
        <div v-else>
            <div class="pagination" v-show="!modelValue">
                <slot name="pagination"></slot>
            </div>
            <div class="buttom" v-show="modelValue" :style="{'height':mobileY+'px'}">
                <el-scrollbar>
                    <slot></slot>
                </el-scrollbar>
            </div>
        </div>

    </div>
</template>

<script>
import { defineComponent, reactive, toRefs } from 'vue';
// 为页数和查看key详情提供动画
export default defineComponent({
    name: 'BtmEditAnim',
    components: {},
    setup(omprops, content) {
        const state = reactive({
            isMobile: false, // 正在调整高度
            mobileY: 300, // 高度
        })
        return toRefs(state)
    },
    props: {
        modelValue: Boolean,
        // 是否高性能模式,减少动画效果
        isEffect: {
            type: Boolean,
            default: false
        }
    },
    computed: {},
    watch: {},
    mounted() {
        document.onmouseup = (e) => {  // 按下鼠标时，初始化处理
            this.isMobile = false
            document.onmousemove = () => { }
        }

    },
    methods: {
        mousedown(d) {
            this.isMobile = true
            var oldY = this.mobileY
            document.onmousemove = (e) => { // 注册鼠标移动事件处理函数
                this.mobileY = oldY - (e.clientY - d.clientY)
                if (this.mobileY < 100) this.mobileY = 100
            };
        },
    },
})
</script>

<style scoped lang="less">
.BtmEditAnim {
    position: relative;
    .back-btn {
        pointer-events: auto;
        position: absolute;
        height: 20px;
        width: 100px;
        top: -25px;
        left: calc(50% - 50px);
        cursor: pointer;
        border-radius: 4px;
        transition: all 0.3s;

        & > div {
            border-radius: 1.5px;
            width: 20px;
            height: 3px;
            background-color: #bbb;
            position: absolute;
            bottom: 3px;
            animation-iteration-count: infinite;
            animation-direction: alternate;
            animation-duration: 0.6s;
            transition: all 0.4s;
            &.t1 {
                transform-origin: 100% center;
                transform: rotate(20deg);
                right: calc(50% - 1px);
                animation-name: example;
                @keyframes example {
                    from {
                        transform: rotate(20deg);
                    }
                    to {
                        transform: rotate(30deg);
                    }
                }
            }
            &.t2 {
                transform-origin: 0 center;
                transform: rotate(-20deg);
                left: calc(50% - 1px);
                animation-name: example2;
                @keyframes example2 {
                    from {
                        transform: rotate(-20deg);
                    }
                    to {
                        transform: rotate(-30deg);
                    }
                }
            }
        }
        &:hover {
            background-color: #eeeeee;
            transform: translateY(5px);
            & > div {
                animation-name: none;
            }
        }

        &.fade- {
            &leave-active,
            &enter-active {
                transition: all 0.3s ease;
            }
            &leave-to,
            &enter-from {
                opacity: 0;
                top: 0;
            }
        }
    }
    .adjust {
        height: 3px;
        // cursor: row-resize;
        cursor: ns-resize;
        position: absolute;
        border-radius: 2px;
        top: -2px;
        left: 50px;
        width: calc(100% - 100px);
        transition: all 0.2s;
        &:hover {
            height: 5px;
            background-color: #3498db;
        }
        &.click {
            height: 5px;
            left: 20px;
            width: calc(100% - 40px);
            background-color: #308dc9;
        }
    }
}
// 页数
.pagination {
    margin-top: 10px;
    // 动画
    &.fade- {
        &leave-from {
            height: 28px;
        }
        &leave-active {
            transition: all 0.3s ease;
        }
        &leave-to,
        &enter-from {
            opacity: 0;
            height: 0px;
            margin-top: 0px;
            transform: scaleY(0.5);
        }
        &enter-active {
            transition: all 0.2s ease;
        }
        &enter-to {
            height: 28px;
        }
    }
}
.buttom {
    // transition: all 3s;
    padding: 10px 6px;
    max-height: 70vh;
    position: relative;
    top: 0;
    // height: 300px;
    // border-top: 1px solid #ddd;
    box-shadow: 0 -1px 2px #ddd;
    border-radius: 10px 10px 0 0;
    // 高动效
    // &.gao {
    &.fade- {
        &leave-active {
            transition: all 0.2s ease;
        }
        &leave-to,
        &enter-from {
            top: 100px;
            height: 0 !important;
            opacity: 0;
            padding: 0 6px;
        }
        &enter-active {
            // 进入
            transition: all 0.4s ease;
        }
    }
}
</style>